<?php

class ui_input_labeled_checkbox extends ui_input
{
	function __construct($name,$label,$checked=false)
	{
		global $ti;
		$this->init(
			__FILE__,
			'input',
			array(
				'type'=>'checkbox',
				'name'=>$name,
				'checked'=>$checked,
				'class'=>'input input_check',
			),
			true
		);
		$this->label = $label;
	}
	
	function pre_render($data)
	{
		parent::pre_render($data);
		$this->generate_id();
		$attribute = ' style="cursor: pointer;" onclick="ti(\''.$this->get('id').'\').checked=(!ti(\''.$this->get('id').'\').checked);"';
		if($this->form)
		{
			if(!$this->form->allow_edit)
			{
				$this->set('disabled','disabled');
				$attribute = '';
			}
		}
		$this->post_outer_html .= '<span'.$attribute.'>&nbsp;'. $this->label.'</span>'.$this->post_outer_html;
	}
	
	function set_checked($state=true)
	{
		if($state)
		{
			$this->attributes['checked']='checked';
		}
		else
		{
			unset($this->v['checked']);
		}
	}
}

?>